package com.bailan.foreat.service.impl;

import com.bailan.foreat.entity.Address;
import com.bailan.foreat.mapper.AddressMapper;
import com.bailan.foreat.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Autowired
    AddressMapper addressMapper;

    @Override
    @Transactional
    public Integer addAddress(Address address) {

        Address newAddress=new Address();
        newAddress.setTel(address.getTel());
        newAddress.setReceiver(address.getReceiver());
        newAddress.setUserId(null);
        newAddress.setStoreId(null);
        newAddress.setProvince(address.getProvince());
        newAddress.setCity(address.getCity());
        newAddress.setArea(address.getArea());
        newAddress.setDetailAddress(address.getDetailAddress());
        newAddress.setEmailCode(address.getEmailCode());
        newAddress.setIsDefault(1);
        newAddress.setStatus(0);

        addressMapper.insert(newAddress);
        Integer addressId = newAddress.getId();

        return addressId;
    }
}
